# coding=utf-8
# https://leetcode.cn/problems/search-insert-position/
from typing import List


class Solution:
    def searchInsert(self, nums: List[int], target: int) -> int:
        r = len(nums)
        l = 0
        while r > l:
            m = (r + l) // 2
            if nums[m] == target:
                return m
            if nums[m] < target:
                l = m + 1
            if nums[m] > target:
                r = m
        return l
